package com.han.hotelplat.comm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.han.hotelplat.comm.Constant;
import com.han.hotelplat.comm.ResponseWrapTo;
import com.han.hotelplat.comm.ResponseWrapTo.CodeType;
import com.han.hotelplat.comm.utils.LogUtil;
import com.han.hotelplat.comm.utils.UploadFile;

@Controller
@RequestMapping("/img/*")
public class ImgController {
	
	/**
	 * 
		 * @description	图片上传公用接口
		 * @author  han1088
		 * @param type 图片归属类型
		 * @param groupid 归属ID
		 * @param img 图片对象
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "uploadImg", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST })
	public String uploadImg(MultipartFile file){
		String saveDir = "hotel";//保存的文件夹名字
		String fileName = file.getOriginalFilename();
		String path = "";
		try {
			path = UploadFile.uploadImg(file, fileName, saveDir);
		} catch (Exception e) {
			LogUtil.info("文件保存失败");
			e.printStackTrace();
		}
		return new ResponseWrapTo(CodeType.success, "图片上传成功", path).toJson();
	}
	
	/**
	 * 
		 * @description	图片上传公用接口
		 * @author  han1088
		 * @param type 图片归属类型
		 * @param groupid 归属ID
		 * @param img 图片对象
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "uploadQuestionImg", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST })
	public String uploadQuestionImg(MultipartFile file){
		String saveDir = "question";//保存的文件夹名字
		String fileName = file.getOriginalFilename();
		String path = "";
		try {
			path = UploadFile.uploadImg(file, fileName, saveDir);
		} catch (Exception e) {
			LogUtil.info("文件保存失败");
			e.printStackTrace();
		}
		return new ResponseWrapTo(CodeType.success, "图片上传成功", path).toJson();
	}
}
